package com.threeonemeeting.list;

import java.util.ArrayList;
import java.util.List;

import com.threeonemeeting.model.CityInfo;

public class CityInfoList {

	public List<CityInfo> listCityInfo = new ArrayList<CityInfo>();

	public void insertCityInfo(CityInfo info) {
		if (info == null)
			return;

		listCityInfo.add(0, info);
	}

	public boolean isExistCity(CityInfo info) {
		if (listCityInfo == null)
			return false;

		for (int i = 0; i < listCityInfo.size(); i++) {
			CityInfo cInfo = listCityInfo.get(i);
			if (cInfo == null)
				continue;

			if (cInfo.strCityName.equalsIgnoreCase(info.strCityName) == true)
				return true;
		}

		return false;
	}

	public void addCityInfo(CityInfo info) {
		if (info == null)
			return;

		if (isExistCity(info) == true)
			return;

		listCityInfo.add(info);
	}

	public void addCityInfo(int nId, int nProvinceId, int nCityId,
			String strCityName) {
		CityInfo info = new CityInfo();
		info.nId = nId;
		info.nProvinceId = nProvinceId;
		info.nCityId = nCityId;
		info.strCityName = strCityName;

		listCityInfo.add(info);
	}

	public int size() {
		return listCityInfo.size();
	}

	public CityInfo get(int nLocation) {
		return listCityInfo.get(nLocation);
	}

	public void clear() {
		listCityInfo.clear();
	}

	public CityInfo getCityInfo(int nId) {
		for (int i = 0; i < listCityInfo.size(); i++) {
			CityInfo info = listCityInfo.get(i);
			if (info == null)
				continue;

			if (info.nId == nId)
				return info;
		}

		return null;
	}

	public CityInfo getCityInfo(int nProvinceId, int nCityId) {
		for (int i = 0; i < listCityInfo.size(); i++) {
			CityInfo info = listCityInfo.get(i);
			if (info == null)
				continue;

			if (info.nProvinceId == nProvinceId && info.nCityId == nCityId)
				return info;
		}

		return null;
	}

	public CityInfo getCityInfo(String strCityName) {
		for (int i = 0; i < listCityInfo.size(); i++) {
			CityInfo info = listCityInfo.get(i);
			if (info == null)
				continue;

			if (info.strCityName.equalsIgnoreCase(strCityName) == true)
				return info;
		}

		return null;
	}
}
